<template>
	<view>
		<view class="item" v-for="(item,index) in list" :key="index" @click="golitian(item)">
			<view class="img" v-if="item.userProfile.avatar">
				<u-badge class="tip" max="99" :count="item.unreadCount"></u-badge>
				<image :src="item.userProfile.avatar" mode=""></image>
			</view>
			<view class="items_cont">
				<view class="items_top">
					<view class="items_name">{{ item.userProfile.nick }}</view>
					<!-- <view v-if="item.lastMessage" class="items_time">{{ item.lastMessage.lastTime | dateFormat }}
					</view> -->
				</view>
				<view class="items_text" v-if="item.lastMessage">
					[{{ item.unreadCount == 0 ? "已读" : "未读" }}]
					<span v-if="item.lastMessage.type == 'TIMImageElem'">[图片]</span>
					<span v-if="item.lastMessage.type == 'TIMSoundElem'">[语音]</span>
					<span v-if="item.lastMessage.type == 'TIMVideoFileElem'">[视频]</span>
					<span v-if="item.lastMessage.type == 'TIMCustomElem'">[引用消息]</span>
					<span v-if="item.lastMessage.type == 'TIMTextElem'">
						{{ item.lastMessage.messageForShow }}</span>
				</view>
			</view>
		</view>
		<view class="kong" v-if="list.length == 0">
			<view class="text">
				暂无数据
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				current: 1,
			};
		},
		onLoad() {
			let that = this
			setTimeout(()=>{
				that.getlist()
			},1000)
			// //等待登录完成再执行
			// let onSdkReady = function(event) {
			//   that.getlist()
			// };
			// uni.$TUIKit.on(uni.$TUIKitEvent.SDK_READY, onSdkReady);
		},
		methods:{
			//获取会话列表
			getlist(){
				uni.$TUIKit.getConversationList().then(res=>{
					this.list = res.data.conversationList
				})
			},
			golitian(item) {
				console.log('跳转')
			    //这里可以直接跳转到聊天页面，需要携带userID
				// uni.navigateTo({
					// url: `/chat/chat?conversationID=C2C${item.userProfile.userID}`
					this.$wanlshop.to(`/pages/IM/chatconversation?conversationID=C2C${111}`)
				// })
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}
	.kong{
		image{
			width: 288rpx;
			height: 288rpx;
		}
		.text{
			margin-top: 20rpx;
		}
		text-align: center;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #ADAAAA;
		line-height: 33rpx;
		margin-top: 200rpx;
	}
	.item {
		padding: 30rpx;
		border-bottom: 1px solid #eee;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		.img {
			width: 80rpx;
			height: 80rpx;
			border-radius: 10rpx;
			position: relative;

			.tip {
				position: absolute;
				right: -35rpx;
				top: -35rpx;
			}

			image {
				width: 80rpx;
				height: 80rpx;
				border-radius: 10rpx;
			}
		}

		.items_cont {
			flex: 1;
			margin-left: 20rpx;
			height: 80rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
		}

		.items_top {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.items_name {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 28rpx;
				color: #000000;
				width: 400rpx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.items_time {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #ADAAAA;
			}
		}

		.items_text {
			width: 580rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #ADAAAA;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			display: flex;
			align-items: center;

			view {
				width: 580rpx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}

		.test {
			margin-left: 20rpx;
		}
	}
</style>
